import { checkByName,checkByCode } from '@/api/admin/post'

let validateName = (rule, value, callback) => {
  if (window.boxType === 'edit') {
    callback()
    return;
  }
  checkByName(value)
    .then(resp => {
      if (resp.data.data > 0) {
        callback(new Error('岗位名称已存在'))
      } else {
        callback()
      }
    })
}
let validateCode = (rule, value, callback) => {
  if (window.boxType === 'edit') {
    callback()
    return;
  }
  checkByCode(value)
    .then(resp => {
      if (resp.data.data > 0) {
        callback(new Error('岗位编码已存在'))
      } else {
        callback()
      }
    })
}
export const tableOption = {
  "border": true,
  "index": true,
  "indexLabel": "序号",
  "stripe": true,
  "menuAlign": "center",
  "align": "center",
  "searchMenuSpan": 6,
  "column": [
    {
      "type": "input",
      "label": "岗位ID",
      "prop": "postId",
      hide: true,
      editDisabled: true,
      addDisplay: false,
      "span": 12
    },	  {
      "type": "input",
      "label": "岗位名称",
      "prop": "name",
      search: true,
      width: '170%',
      overHidden: true,
      "span": 12,
      rules: [
        { required: true, message: '岗位名称不能为空', trigger: 'blur'},
        { validator: validateName, trigger: 'blur'}
        ]
    },	{
      "type": "input",
      "label": "岗位标识",
      "prop": "code",
      width: '150%',
      search: true,
      "span": 12,
      rules: [
        { required: true, message: '岗位编码不能为空', trigger: 'blur'},
        { validator: validateCode, trigger: 'blur'}
      ]
    },	  {
      "type": "switch",
      "label": "状态",
      "prop": "useFlag",
      search: true,
      width: '80%',
      row: true,
      mock:{
        type:'useFlag'
      },
      span: 12,
      dicData: [{
        label: '启用',
        value: 'Y'
      }, {
        label: '关闭',
        value: 'N'
      }]
    },  {
      "type": "number",
      "label": "显示顺序",
      "prop": "sort",
      hide: true,
      "span": 12,
      rules: [{
        required: true,
      }]
    },	  {
      "type": "textarea",
      "label": "岗位描述",
      "prop": "remark",
      width: '280%',
      overHidden: true,
      "span": 12,
      rules: [{
        required: true,
      }]
    } ,	  {
      "type": "input",
      "label": "创建时间",
      "prop": "createdTime",
      editDisabled: true,
      addDisplay: false,
      width: '160%',
      "span": 12
    },	  {
      "type": "input",
      "label": "创建者",
      "prop": "createdBy",
      editDisabled: true,
      addDisplay: false,
      width: '145%',
      "span": 12
    },	  {
      "type": "input",
      "label": "修改者",
      "prop": "updatedBy",
      editDisabled: true,
      addDisplay: false,
      hide: true,
      "span": 12
    },	  {
      "type": "input",
      "label": "修改时间",
      "prop": "updatedTime",
      hide: true,
      editDisabled: true,
      addDisplay: false,
      "span": 12
    } ]
}
